package org.osforce.platform.action;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.opensymphony.xwork2.Preparable;

public abstract class SpringBasedAction extends BaseAction implements Preparable{

	private static final long serialVersionUID=-7267643838799010751L;

	public SpringBasedAction(){
	}

	protected WebApplicationContext getWebApplicationContext(){
		return WebApplicationContextUtils
				.getRequiredWebApplicationContext(getServletContext());
	}

	protected <T> T getBeanByType(Class<T> requiredType){
		return getWebApplicationContext().getBean(requiredType);
	}

	protected <T> T getBeanByNameAndType(String name,Class<T> requiredType){
		return getWebApplicationContext().getBean(name,requiredType);
	}
}
